package org.reyton.action;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;
import org.reyton.entity.BizClaimVoucher;
import org.reyton.entity.BizClaimVoucherDetail;
import org.reyton.entity.PageBean;
import org.reyton.entity.SysEmployee;
import org.reyton.service.BizClaimVoucherDetailService;
import org.reyton.service.BizClaimVoucherService;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

/**
 * 业务审核控制器
 * Created by reyton on 16-12-14.
 */
@Controller("bizCheckResultAction")
@Scope("prototype")
public class BizCheckResultAction extends ActionSupport {
    @Resource(name = "bizClaimVoucherService")
    private BizClaimVoucherService bizClaimVoucherService;
    @Resource(name = "bizClaimVoucherDetailService")
    private BizClaimVoucherDetailService bizClaimVoucherDetailService;

    private PageBean<BizClaimVoucher> pageBean;
    private BizClaimVoucher bizClaimVoucher;
    private List<BizClaimVoucherDetail> bizClaimVoucherDetails;

    private int pageSize = 5;
    private int pageIndex = 1;

    /***
     * 查看报销单
     * @return 控制器处理结果
     * @throws Exception
     */
    public String checkView() throws Exception {
        bizClaimVoucher = bizClaimVoucherService.findById(bizClaimVoucher);
        bizClaimVoucherDetails = bizClaimVoucherDetailService.findDetails(bizClaimVoucher);
        ServletActionContext.getRequest().getSession().setAttribute("bizClaimVoucher",bizClaimVoucher);
        ServletActionContext.getRequest().getSession().setAttribute("bizClaimVoucherDetails",bizClaimVoucherDetails);
        return "checkView_success";
    }

    /***
     * 分页查询待审列表
     * @return 控制器的处理结果
     * @throws Exception
     */
    public String checkList() throws Exception {
        SysEmployee sysEmployee = (SysEmployee) ServletActionContext.getRequest().getSession().getAttribute("EMP");
        pageBean = bizClaimVoucherService.findPageByNextDealSn(sysEmployee, pageSize, pageIndex);
        ServletActionContext.getRequest().getSession().setAttribute("pageBean", pageBean);
        return "checkList_success";
    }

    public void setBizClaimVoucherService(BizClaimVoucherService bizClaimVoucherService) {
        this.bizClaimVoucherService = bizClaimVoucherService;
    }

    public List<BizClaimVoucherDetail> getBizClaimVoucherDetails() {
        return bizClaimVoucherDetails;
    }

    public void setBizClaimVoucherDetails(List<BizClaimVoucherDetail> bizClaimVoucherDetails) {
        this.bizClaimVoucherDetails = bizClaimVoucherDetails;
    }

    public PageBean<BizClaimVoucher> getPageBean() {
        return pageBean;
    }

    public void setPageBean(PageBean<BizClaimVoucher> pageBean) {
        this.pageBean = pageBean;
    }

    public BizClaimVoucher getBizClaimVoucher() {
        return bizClaimVoucher;
    }

    public void setBizClaimVoucher(BizClaimVoucher bizClaimVoucher) {
        this.bizClaimVoucher = bizClaimVoucher;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }
}
